package tk.winshu.argumentresolver.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import tk.winshu.argumentresolver.resovler.CurrentUser;
import tk.winshu.argumentresolver.model.User;
import tk.winshu.argumentresolver.service.IUserService;

import javax.servlet.http.HttpServletRequest;

import static tk.winshu.argumentresolver.resovler.CurrentUserResolver.getJessionid;

/**
 * @author Kevin
 * @since 2019/5/31
 */
@RestController
public class ResolverController {

    @Autowired
    private IUserService userService;

    @GetMapping("/index")
    @ResponseBody
    public boolean index(HttpServletRequest request) {
        String jessionid = getJessionid(request);
        return userService.login(jessionid, "admin", "123456");
    }

    @GetMapping("/main")
    @ResponseBody
    public User main(@CurrentUser User current) {
        return current;
    }
}
